package com.ruoyi.hospital.controller.commons;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.common.Commonexp;
import com.ruoyi.hospital.service.common.ICommonexpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常用语Controller
 * 
 * @author wendao
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/hospital/commonexp")
public class CommonexpController extends BaseController
{
    @Autowired
    private ICommonexpService commonexpService;

    /**
     * 查询常用语列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:commonexp:list')")
    @GetMapping("/list")
    public TableDataInfo list(Commonexp commonexp)
    {
        commonexp.setSelectType(2);
        startPage();
        List<Commonexp> list = commonexpService.selectCommonexpList(commonexp);
        return getDataTable(list);
    }

    /**
     * 导出常用语列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:commonexp:export')")
    @Log(title = "常用语", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Commonexp commonexp)
    {
        List<Commonexp> list = commonexpService.selectCommonexpList(commonexp);
        ExcelUtil<Commonexp> util = new ExcelUtil<Commonexp>(Commonexp.class);
        util.exportExcel(response, list, "常用语数据");
    }

    /**
     * 获取常用语详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:commonexp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(commonexpService.selectCommonexpById(id));
    }

    /**
     * 新增常用语
     */
    @PreAuthorize("@ss.hasPermi('hospital:commonexp:add')")
    @Log(title = "常用语", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Commonexp commonexp)
    {
        return toAjax(commonexpService.insertCommonexp(commonexp));
    }

    /**
     * 修改常用语
     */
    @PreAuthorize("@ss.hasPermi('hospital:commonexp:edit')")
    @Log(title = "常用语", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Commonexp commonexp)
    {
        return toAjax(commonexpService.updateCommonexp(commonexp));
    }

    /**
     * 删除常用语
     */
    @PreAuthorize("@ss.hasPermi('hospital:commonexp:remove')")
    @Log(title = "常用语", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(commonexpService.deleteCommonexpByIds(ids));
    }
}
